package cn.hadron.aa.action;
import java.util.*;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.hadron.aa.entity.Article;
import cn.hadron.aa.entity.Channel;
import cn.hadron.aa.service.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@Controller  //默认值indeAction
@Scope("prototype") //每一个请求有一个单独的Action来处理
public class IndexAction extends ActionSupport {
	private List<Channel> clist=new ArrayList<>();
	private Map<Channel,List<Article>> ca = new HashMap<>();
	@Resource(name="articleService")
	private ArticleService as;
	@Resource(name="channelService")
	private ChannelService cs;
	@Action(value="index", results={@Result(name="success",location="/index2.jsp")})
	@Override
	public String execute() throws Exception {
		clist=cs.getAllChannel();
		ActionContext.getContext().getSession().put("clist", clist);
		for(Channel c:clist){
			List<Article> alist=new ArrayList<>();
			alist=as.getPager(c.getId(), 1, 6).getData();
			ca.put(c,alist);
			//System.out.println(c.getName()+":"+alist);
		}
		return SUCCESS;
	}
	public ArticleService getAs() {
		return as;
	}
	public void setAs(ArticleService as) {
		this.as = as;
	}
	public List<Channel> getClist() {
		return clist;
	}
	public void setClist(List<Channel> clist) {
		this.clist = clist;
	}
	public Map<Channel, List<Article>> getCa() {
		return ca;
	}
	public void setCa(Map<Channel, List<Article>> ca) {
		this.ca = ca;
	}
}